define(['moment'], function () {
    return ['$scope', '$rootScope', '$filter', '$stateParams', '$mdDialog', 'config', 'MMWService', '$calculater','$mddProvider',
        function ($scope, $rootScope, $filter, $stateParams, $mdDialog, config, $MMWService, $calculater,$mddProvider) {
            $scope._event = {};
            dialog = {};
			$scope._fn={};
            $scope.init = function () { 
                // 20230303 modify by Alan for#: module_setting卡控
                $scope.PTC_ASC = config.cache.module_setting.PTC_ASC;
                $MMWService.PNIGList = {};
                $scope.warehouseInfo = {
                    type: '', product_warehouse: '', storage: '',
                    plot_info_detail: [],
                    wo_no: '', item_no: '', plot_no: '', erp_doc_type: ''
                };
                //$scope.plot_info_detail=[];
                $scope.type = '1';
                $scope.selectedList = [];

                $scope.warehouseInfo.item_no = '';
                $scope.warehouseInfo.item_name = '';
                $scope.warehouseInfo.wo_no = '';

                $scope.warehouseInfo.select_type = 3;

                $scope.list_filter = {};
                $scope.filterSH = {};
                //20170612 modify by Dustdusk for 新增作廢功能
                //$scope.feedback_type = [0, 1, 2, 3, 4];
                if(!config.cache.permissions || config.cache.permissions.indexOf('B0225')!=-1){
                    $scope.isB0225 = true;
                }
            };

            $scope.back = function () {
                $scope.$root.hideMenu();
                $scope.$root.changeProgram('home', true);
            };

            //20170505 modify by Dustdusk for 入庫查詢可以不用輸入條件
            $scope._fn['search'] = {
				click:()=>{
					var content = {
                    wo_no: $scope.warehouseInfo.wo_no,
                    item_no: $scope.warehouseInfo.item_no,
                    type: '1',
                    do_flag:$scope.do_flag
                };
                warehousePlotInfoGet(content, function (response) {
                    if(response && response.length > 0){
                        //不良品先判斷是否有選取資料存在再決定是否詢問
                        if($scope.selectedList.length == 0){
                            $scope.list_filter = {};
                            $scope.filterSH = {};
                            $scope.warehouseInfo.plot_info_detail = response;
                            $scope.warehouseInfo.plot_info_detail.forEach(function (detail) {
                                detail.checked = false;
                                detail.judge_qty = detail.qty;
                            });
                        } else if($scope.selectedList.length != 0){
                            $scope.$root.showConfirm($filter('translate')('B0402.msg.keep_on_hold'),
                                function(dialog){
                                    $scope.list_filter = {};
                                    $scope.filterSH = {};
                                    dialog.hide();
                                    $scope.warehouseInfo.plot_info_detail = response;
                                    $scope.warehouseInfo.plot_info_detail.forEach(function (detail) {
                                        detail.judge_qty = detail.qty;
                                    });
                                    $scope.selectedList = [];
                                },
                                function(dialog){
                                    dialog.hide();
                                }
                            );
                        }
                    } else {
                        $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                    }
                });

				}

            };

            $scope.ClickDoFlag = function(){
                if($scope.selectedList.length>0){
                    $scope.$root.showAlert($filter('translate')('B0402.msg.already_selected'));
                } else {
                    if($scope.do_flag == 1){
                        $scope.do_flag = 0;
                    } else {
                        $scope.do_flag = 1;
                    }
                    $scope.warehouseInfo.plot_info_detail = [];
                    $scope.selectedList = [];
                }
            };

            $scope._fn['Confirm'] = {
                click: () => {
				// 20221206 modify by Alan for M#112097:  當ReasonType==16 or 17時，不允許讓步處理
                let fqcList = $scope.selectedList.filter((info) => info.ReasonType == 16 || info.ReasonType == 17);
                if(fqcList.length > 0 && $scope.warehouseInfo.select_type == 1) {
                    var msg = '';
                    fqcList.forEach((item) => {
                        msg += $filter('translate')('B0402.msg.fqc_result_cant_concession', { lotno: item.plot_no, reason: item.error_desc }) + '</br>'
                    })
                    $scope.$root.showAlert(msg);
                    return;
                }
                if($scope.warehouseInfo.select_type == 2){
                    //誤判
                    $scope.warehouseInfo.product_warehouse = '';//成品庫
                    $scope.warehouseInfo.product_warehouse_name = '';//成品庫
                    $scope.warehouseInfo.storage = ''; //儲位
                    $scope.warehouseInfo.storage_display = ''; //儲位
                    $scope.warehouseInfo.erp_doc_type = '';//ERP單別
                    warehousePlotProcess_Imp();
                } else if($scope.warehouseInfo.select_type == 3 || $scope.warehouseInfo.select_type == 4){
                    //報廢入庫 or 不良品
                    $scope.openStorage();
                } else {
                    //重工處理/讓步處理
                    var options = {
                        plot_detail : $scope.selectedList,
                        option : $scope.warehouseInfo.select_type //重工:0/讓步:1
                    }
                    var msg = reworkOptCheck(options);
                    if(msg == ''){
                        openRework(options, function(){
                            //20170330 modify by megabytes for 確認存取完後清空
                            $scope.warehouseInfo.plot_info_detail = [];
                            $scope.warehouseInfo.item_no = '';
                            $scope.warehouseInfo.item_name = '';
                            $scope.warehouseInfo.wo_no = '';
                            $scope.warehouseInfo.plot_no = '';
                            $scope.selectedList = [];
                        });
                    }else{
                        $rootScope.showAlert(msg);
                    }
                }
				}

            };

            // 20230309 modify by Alan for#123998: 'iconButton'使用_fn方法
            $scope._fn['plot_info_detail.add'] = {
                icon: 'image/icons/add.png',
                style: {'background': '#63A9DD', 'border-radius': '50%', 'width': '28px', 'height': '28px', 'min-width': '28px', 'font-size': '0px', 'box-shadow': 'none'},
                click: (model, name, args) => $scope.itemCheck(args.index, args.eventScope)
            }

            $scope._fn['selectedList.remove'] = {
                icon: 'image/icons/delete1.png',
                click: (model, name, args) => $scope.returnTarget(args.index, args.eventScope)
            }

            //20170405 modify by megabytes for 內存外顯修改
            //20170410 modify by megabytes for 改為皆顯示no
            //20170602 modify by Dustdusk for 開窗調整
            //20170602 modify by Dustdusk for 開窗取消
            //取得產品編號
            $scope._event['item_no'] = {
				click:()=>{
				//20170704 modify by Dustdusk for 入庫產品清單查詢優化
                $MMWService.showQueryListPNIG({
                    //page_mode: 19,
                    form_name: 'PageNo_11',
                    key:'page_no',
                    pageRecord:50,
                    condition: [
                        {name:$filter('translate')('common.queryList.item_c'), column_name:'B.ProductNo', query_mode:'2', value:$scope.warehouseInfo.item_no},
                        {name:$filter('translate')('common.queryList.item_n'), column_name:'B.ProductName', query_mode:'2', value:''}
                    ],
                    header: [
                        {label:$filter('translate')('common.queryList.item_c'), code:'page_no'},
                        {label:$filter('translate')('common.queryList.item_n'), code:'page_name'}
                    ],
                    selectCode:$scope.warehouseInfo.item_no,
                    confirm : function(selectItem){
                        $scope.warehouseInfo.item_no = selectItem.page_no;
                        $scope.warehouseInfo.item_name = selectItem.page_name;
                        $scope.warehouseInfo.wo_no = '';
                    }
                });
				}

            };

            //取得工單編號
            //20170602 modify by Dustdusk for 拿掉一定要輸入產品編號的限制
            //20170602 modify by Dustdusk for 開窗取消
            $scope._event['wo_no']= {
				click:()=>{
				//20170704 modify by Dustdusk for 入庫工單清單查詢優化
                $MMWService.showQueryListPNIG({
                    //page_mode: 21,
                    form_name: 'PageNo_15',
                    pageRecord:50,
                    condition: [
                        {name:$filter('translate')('common.queryList.wo_c'), column_name:'C.MoNo', query_mode:'2', value:$scope.warehouseInfo.wo_no}
                    ],
                    header: [
                        {label:$filter('translate')('common.queryList.wo_c'), code:'page_no'}
                    ],
                    setCondition:function(conditions){
                        if($scope.warehouseInfo.item_name != '')
                            conditions.push({column_name:'B.ProductNo', query_mode:'0', value: $scope.warehouseInfo.item_no, merge_condition_model : 'AND'});

                        return conditions;
                    },
                    selectCode:$scope.warehouseInfo.wo_no,
                    confirm : function(selectItem){
                        $scope.warehouseInfo.wo_no = selectItem.page_no;
                    }
                });
				}
            };

            $scope._event['plot_no'] = {
                change: (plot_no, $event) => {
                    if ($event.event.keyCode == 13) {
                        $scope._fn['choose'].click();
                        $scope.$root.focusById('plot_no');
                    }
                }
            };
            $scope._event['selectedList.judge_qty'] = {
                click: (item, $event) => {
                    $scope.input_judge_qty($event.event, $event.eventScope)
                }
            };
           // $scope.BarcodeScanner = function($event){
           //};

            $scope._fn['choose'] = {
				click:()=>{
					                var targetArray = [];
                for (var i = 0; i < $scope.warehouseInfo.plot_info_detail.length; i++) {
                    if ($scope.warehouseInfo.plot_info_detail[i].plot_no.indexOf($scope.warehouseInfo.plot_no) != -1) {
                        var target = $scope.warehouseInfo.plot_info_detail[i];
                        var isOK = true;

                        for(var j = 0 ; j < $scope.selectedList.length ; j++){
                            //20180425 modify by Dustdusk for 相同生產批不同不良原因要能選擇
                            //20180808 modfiy by Dustdusk for 改為使用rowid 判斷是否同一筆
                            if($scope.selectedList[j].rowid == target.rowid){
                                isOK = false;
                                break;
                            }
                        }

                        if(isOK){
                            target.checked = true;
                            $scope.selectedList.push(target);
                            targetArray.push(target);
                        }
                        //$scope.warehouseInfo.plot_info_detail.splice($scope.warehouseInfo.plot_info_detail.indexOf(target), 1);
                    }
                }

                targetArray.forEach(function(target){
                    $scope.warehouseInfo.plot_info_detail.splice($scope.warehouseInfo.plot_info_detail.indexOf(target), 1);
                })
				}

            };


            //20170329 modify by megabytes for 刪除佇列部分也需要判斷是否重複問題
            $scope.returnTarget = function (index, data) {
                var searchrepeat = false;
                for(var i = 0 ; i < $scope.warehouseInfo.plot_info_detail.length ; i++){
                    //20180808 modfiy by Dustdusk for 改為使用rowid 判斷是否同一筆
                    if($scope.warehouseInfo.plot_info_detail[i].rowid == data.rowid){
                        searchrepeat = false;
                        break;
                    }
                }

                if(searchrepeat){
                    data.checked = !data.checked;
                    $scope.selectedList.splice($scope.selectedList.indexOf($scope.selectedList[index]), 1);
                }else{
                    data.checked = !data.checked;
                    $scope.warehouseInfo.plot_info_detail.push(data);
                    $scope.selectedList.splice($scope.selectedList.indexOf($scope.selectedList[index]), 1);
                }
            };


            $scope.itemCheck = function (index, data) {
                var msg = '';
                for(var i = 0 ; i < $scope.selectedList.length ; i++){
                    //20180425 modify by Dustdusk for 相同生產批不同不良原因要能選擇
                    //20180808 modfiy by Dustdusk for 改為使用rowid 判斷是否同一筆
                    if($scope.selectedList[i].rowid == data.rowid){
                        msg = $filter('translate')('B0402.msg.repeat');
                        break;
                    }
                }

                if(msg != ''){
                    $scope.$root.showAlert(msg);
                } else {
                    data.checked = !data.checked;
                    $scope.selectedList.push(data);
                    $scope.warehouseInfo.plot_info_detail.splice($scope.warehouseInfo.plot_info_detail.indexOf(data), 1);
                }
            };


            $scope.openStorage = function () {
                $mddProvider.UseForm('B0402_SearchPlot',() => {
                    $mdDialog.dialog(
                        'module/moduleB/program/B04/B0402/B0402_SearchPlot.tmp.html',
                        storageController
                    )
                });
            };


            // 重工參數檢驗
            function reworkOptCheck(options){
                var msg = '';
                if(options.option == 0 || options.option == 1){
                    // 取 plot_detail 的第一筆工單號來過濾整個 plot_detail，過濾前後若plot筆數不同表示參雜了其他工單號的批號
                    var sample_wo_no = options.plot_detail[0].wo_no;
                    var filtered_plot_detail = $filter('filter')(options.plot_detail, {wo_no: sample_wo_no}, true);
                    if(options.plot_detail.length != filtered_plot_detail.length){
                        msg = $filter('translate')('B0402.msg.wo_is_different'); //工單號不相同，不允許此操作
                    }
                }
                return msg;
            }

            // 重工開窗(已支援不同工單號，但目前先控卡不同工單不能開窗)
            function openRework(options, callback){
                if(options.plot_detail && options.plot_detail.length != 0){
                    var sample_wo_no = options.plot_detail[0].wo_no;
                    var plot_detail = [];
                    var next_plot_detail = [];

                    options.plot_detail.forEach(function(plot){
                        if(plot.wo_no == sample_wo_no){
                            plot_detail.push(plot);
                        }else{
                            next_plot_detail.push(plot); //不同的工單號的plot，保留到下次重工開窗
                        }
                    });
                    options.plot_detail = next_plot_detail;
                    $mdDialog.serviceDialog('B0213Service', {
                        plot_detail : plot_detail,
                        option : options.option,
                        parent : 'B0402',
                        feedback : function(){
                            openRework(options, callback);
                        }
                    });                    
                }else{
                    if(callback)
                        callback();
                }
            }


            function storageController(dialog) {
                let _hide = dialog.hide;
                //20230111 add by linzh for M#:125770 开窗前先清空旧选择
                $scope.warehouseInfo.product_warehouse = '';
                $scope.warehouseInfo.storage = '';
                $scope.warehouseInfo.erp_doc_type = '';

                var controller = {
                    type: '1',
                    warehouseInfo: $scope.warehouseInfo,
                    _event: {
                        'product_warehouse': {//成品庫
                            click: () => {
                                // 良品 & 不良品 = 1 , 報廢 = 3
                                pageNumberInfoGet({
                                    //page_mode: '13',
                                    form_name: 'PageNo_6',
                                    query_condition_info: [
                                        { column_name: 'InventoryType', query_mode: '0', value: ($scope.warehouseInfo.select_type == 3) ? 3 : 1 }
                                    ]
                                }, function (response) {
                                    $scope.$root.showSelect({
                                        title: $filter('translate')('B0402.otherTitle.column1'),
                                        label: function (item) {
                                            return item.page_no + ' (' + item.page_name + ')';
                                        },
                                        code: 'page_no',
                                        selectCode: $scope.warehouseInfo.product_warehouse,
                                        list: response,
                                        confirm: function (item, dialog) {
                                            dialog.hide();
                                            $scope.warehouseInfo.product_warehouse_name = item.page_name;
                                            $scope.warehouseInfo.product_warehouse = item.page_no;

                                            $scope.warehouseInfo.storage = '';
                                            $scope.warehouseInfo.storage_display = '';
                                        }
                                    });
                                });
                            }
                        },
                        'storage': {//儲位
                            click: () => {
                                if ($scope.warehouseInfo.product_warehouse != '') {
                                    pageNumberInfoGet({
                                        //page_mode: 14,
                                        form_name: 'PageNo_7',
                                        query_condition_info: [
                                            { column_name: 'InventoryNo', query_mode: '0', value: $scope.warehouseInfo.product_warehouse }
                                        ]
                                    }, function (response) {
                                        $scope.$root.showSelect({
                                            title: $filter('translate')('B0402.otherTitle.column1'),
                                            label: function (item) {
                                                return item.page_no + ' (' + item.page_name + ')';
                                            },
                                            code: 'page_no',
                                            selectCode: $scope.warehouseInfo.storage,
                                            list: response,
                                            confirm: function (item, dialog) {
                                                dialog.hide();
                                                $scope.warehouseInfo.storage = item.page_no;
                                                $scope.warehouseInfo.storage_display = item.page_name;
                                            }
                                        });
                                    });
                                } else {
                                    $scope.$root.showAlert($filter('translate')('B0402.msg.product_warehouse_empty'));
                                }
                            }
                        },
                        'erp_doc_type': {
                            click: () => {
                                $rootScope.showQueryList({
                                    pageRecord: 50,
                                    header: [
                                        { label: $filter('translate')('B0216.queryList.column3_1'), code: 'page_no' },
                                        { label: $filter('translate')('B0216.queryList.column3_2'), code: 'page_name' }
                                    ],
                                    query: function (conditions, feedback) {
                                        $MMWService.sendToServer({
                                            uri: 'ServicesSTD.Module_SYS.erp_document_type_get',
                                            content: { doc_type: ($scope.warehouseInfo.select_type == 4) ? '1' : '2' }, // 不良品入庫=入庫單，報廢入庫=報廢單
                                            success: function (data) {
                                                feedback(data);
                                            }
                                        });
                                    },
                                    selectCode: $scope.warehouseInfo.erp_doc_type,
                                    confirm: function (selectItem, dialog) {
                                        $scope.warehouseInfo.erp_doc_type = selectItem.page_no;
                                        dialog.hide();
                                    }
                                });
                            }
                        }
                    },
                    _fn:{
                        'confirm': {
                            click:()=>{
                                _hide();
                                warehousePlotProcess_Imp();
                            }
                        }
                    },
                    hide: function () {
                        $scope.warehouseInfo.product_warehouse_name = '';
                        $scope.warehouseInfo.product_warehouse = '';
                        $scope.warehouseInfo.storage = '';
                        $scope.warehouseInfo.storage_display = '';
                        $scope.warehouseInfo.erp_doc_type = '';
                        _hide();
                    }
                }
                return controller;
            }

            //取得單號
            // 1 工單編號 6產品編號 13成品庫 14儲位
            function pageNumberInfoGet(content, feedback) {
                $MMWService.pageNumberInfoGet(
                    content
                    , function (itemList) {
                        feedback(itemList);
                });
            }


            //取得待入庫資料
            //type 0:良品  1:不良品
            function warehousePlotInfoGet(content, feedback) {
                $MMWService.sendToServer({
                    uri: 'ServicesSTD.Module_WIP.warehouse_plot_info_get',
                    content: content,
                    success: function (data) {
                        feedback(data.warehouse_plot_info_get);
                    }
                });
            }

            function warehousePlotProcess_Imp() {
                var msg = '';
                var content = {
                    type: '1',
                    product_warehouse: $scope.warehouseInfo.product_warehouse,
                    storage: $scope.warehouseInfo.storage,
                    erp_doc_type: $scope.warehouseInfo.erp_doc_type,
                    do_flag: $scope.do_flag,
                    plot_info_detail: []
                };
                if($scope.warehouseInfo.select_type == 2){ //誤判
                    content.type = 2;
                } else if($scope.warehouseInfo.select_type == 4){ //不良品
                    content.type = 4;
                }
                for(var index in $scope.selectedList){
                    var item = $scope.selectedList[index];
                    // 20210422 modifyBy 14581 for M#89226 : 不良品判定增加傳遞線邊倉參數
                    // 20221206 modify by Alan for M#112097:  增加回傳ReasonType
                    // 20230321 modify by ShengKun for M# 0119704：添加SNList
                    var plot_info_detail = {
                        plot_no: item.plot_no,
                        op_no: item.op_no,
                        lot_serial: item.lot_serial,
                        plot_qty: item.qty,
                        error_no: item.error_no,
                        log_group_serial: item.log_group_serial,
                        InventoryNo: item.inventoryno,
                        mes_inventoryNo: item.mes_inventoryNo,
                        ReasonType: item.ReasonType,
                        SNList: [{
                            FGDINNO: "",
                            LotNo: item.plot_no,
                            OPNo: item.op_no,
                            PCSNo: item.pcs_no,
                            PRODUCTNO: "",
                            PRODUCTVERSION: ""
                        }]
                    };

                    if(item.judge_qty == undefined || item.judge_qty == 0){
                        msg = $filter('translate')('B0402.msg.judge_qty_empty');
                        break;
                    } else if(item.judge_qty == undefined || item.judge_qty == 0){
                        msg = $filter('translate')('B0402.msg.judge_qty_gt');
                        break;
                    }
                    plot_info_detail.plot_qty = item.judge_qty;

                    if(item.joint_trigger == undefined){
                        plot_info_detail.joint_trigger = 'N';
                    } else {
                        plot_info_detail.joint_item_no = item.joint_item_no;
                        plot_info_detail.joint_item_unit_no = item.joint_item_unit_no;
                        plot_info_detail.joint_trigger = 'Y';
                    }

                    content.plot_info_detail.push(plot_info_detail);
                    //content.op_no = item.op_no;
                }
                if(msg == ''){
                    warehousePlotProcess(content, function(data, response){
                        //20180514 modify by Dustdusk for M#46940:入庫完成的訊息由後台提供 請抓 response.Message
                        var msg = $filter('translate')('B0402.msg.process_success');
                        if(response.Message != undefined && response.Message!=''){
                            msg = response.Message;
                        }
                        //20170330 modify by megabytes for 確認存取完後清空
                        $scope.warehouseInfo.plot_info_detail = [];
                        $scope.warehouseInfo.item_name = '';
                        $scope.warehouseInfo.wo_no = '';
                        $scope.warehouseInfo.plot_no = '';
                        $scope.warehouseInfo.item_no = '';
                        $scope.selectedList = [];
                        $scope.$root.showToast(msg);
                    });
                } else {
                    $scope.$root.showAlert(msg);
                }
            }

            //送出確定的待入庫資料
            //type 0:良品 1:不良品
            function warehousePlotProcess(content, callback) {
                $MMWService.sendToServer({
                    uri: 'ServicesSTD.Module_WIP.warehouse_plot_process',
                    content: content,
                    success: function (data, response) {
                        if(callback)
                            callback(data, response);
                    }
                });
            }

            //20211005 modify by Jason for M#0096757: [懋莉] 不良品入庫需可變更品號
            $scope._event['feedback_type'] = {
                changed: (type) => {
                    // $scope.changeSelectType = function (type) {

                        if ($scope.warehouseInfo.select_type == 4 && $scope.selectedList.length > 0) {
                            $scope.selectedList.forEach(selectItem => {
                                if (selectItem.joint_trigger == "Y") {
                                    $scope.$root.showAlert($filter('translate')('B0402.msg.joint_only'));
                                    $scope.selectedList = [];
                                }
                            });

                        }
                        $scope.warehouseInfo.select_type = type;
                    //};
                }
            };


            $scope.input_judge_qty = function (event, item) {
                var target = event.currentTarget;
                angular.element(target).addClass('is-focus');
                $calculater.open(function (num, dialog) {
                        angular.element(target).removeClass('is-focus');
                        if(num == 0){
                            $scope.$root.showAlert($filter('translate')('B0402.msg.judge_qty_empty'));
                        } else if ((+num) > (+item.qty)){
                            $scope.$root.showAlert($filter('translate')('B0402.msg.judge_qty_gt'));
                        } else {
                            item.judge_qty = num;
                            dialog.hide();
                        }
                    },
                    function (dialog) {
                        angular.element(target).removeClass('is-focus');
                        dialog.hide();
                    },
                    {
                        defaultNum: item.judge_qty,
                        decimal: false
                    });
            };

            $scope.product_change = function(event, item){
                $mdDialog.serviceDialog('B0223Service',{
                    parent : 'B0402',
                    plotItem : item,
                    do_flag: 1,
                    close : function(newItem){
                        item.item_no = item.joint_item_no; //  20240221 modify by shiwl for #0157806: [sMES] 聯產品入庫時已選取好的品號再次點進選單後，點選關閉視窗，品號會跳回原生產批品號 [應用奈米]
                        item.item_name = newItem.item_name;
                        item.item_unit_no = newItem.item_unit_no;
                        item.item_ver = newItem.item_ver;
                    },
                    feedback : function(newItem){
                        item.old_item_no = item.item_no;
                        item.old_item_name = item.item_name;
                        item.old_item_unit_no = item.item_unit_no;
                        item.old_item_ver = item.item_ver;

                        item.joint_item_no = item.item_no = newItem.joint_item_no;
                        item.item_name = newItem.joint_item_name;
                        item.joint_item_unit_no = item.item_unit_no = newItem.joint_item_unit_no;
                        item.item_ver = newItem.joint_item_ver;
                        item.joint_trigger = 'Y';
                    }
                });
            };

            $scope.callB0225 = function(item){
                $mdDialog.serviceDialog('B0225Service',{
                    parent:'B0402',
                    plotItem : item,
                    callback : function(){
                        $scope._fn['search'].click();
                    }
                });
            };
        }
    ];
});
